package business {

    import com.adobe.cairngorm.business.ServiceLocator;
    
    import mx.collections.*;
    import mx.rpc.*;
    import mx.rpc.remoting.*;
	
    public class GameDelegate
    {
		private var responder:Object;
        private var service:RemoteObject;

        public function GameDelegate(re:Object)
        {
	        this.service = ServiceLocator.getInstance().getRemoteObject("gameService");
            this.responder = re;
        }
        
        public function getConfigs():void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.getConfigs();
            itemResponder = new ItemResponder(responder["getConfigsResult"],responder["fault"] );
            token.addResponder(itemResponder);
        }

        public function getGames(page:int):void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.getGames(page);
            itemResponder = new ItemResponder(responder["getGamesResult"],responder["fault"] );
            token.addResponder(itemResponder);
        }

        public function getGamesBySearch(type:String, pattern:String, page:int):void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.getGamesBySearch(type, pattern, page);
            itemResponder = new ItemResponder(responder["getGamesResult"],responder["fault"] );
            token.addResponder(itemResponder);
        }

        public function addGame():void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.addGame();
            itemResponder = new ItemResponder(responder["addGameResult"],responder["fault"] );
            token.addResponder(itemResponder);
        }

        public function removeGames(page:int,ids:Array):void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.removeGames(page,ids);
            itemResponder = new ItemResponder(responder["removeGamesResult"],responder["fault"] );
            token.addResponder(itemResponder);
        }

        public function updateGame(updated:Object):void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.updateGame(updated);
            itemResponder = new ItemResponder(responder["updateGameResult"],responder["fault"] );
            token.addResponder(itemResponder);
        }
        
        public function getGameContentType(page:int):void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.getGameContentType(page);
            itemResponder = new ItemResponder(responder["getGameContentTypeResult"],responder["fault"] );
            token.addResponder(itemResponder);
        }
        
        public function addGameContentType():void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.addGameContentType();
            itemResponder = new ItemResponder(responder["addGameContentTypeResult"],responder["fault"] );
            token.addResponder(itemResponder);
        }

        public function updateGameContentType(page:int,updated:Object):void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.updateGameContentType(page,updated);
            itemResponder = new ItemResponder(responder["updateGameContentTypeResult"],responder["fault"] );
            token.addResponder(itemResponder);
        }
        
        public function removeGameContentType(page:int,ids:Array):void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.removeGameContentType(page,ids);
            itemResponder = new ItemResponder(responder["removeGameContentTypeResult"],responder["fault"] );
            token.addResponder(itemResponder);
        }     
        
        public function mergeGame(fromid:int,toid:int):*
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.mergeGame(fromid,toid);
            itemResponder = new ItemResponder(responder["mergeGameResult"],responder["fault"] );
            token.addResponder(itemResponder);        	
        }
        
        public function getIdByGameName( name:String ):void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.getIdByGameName(name);
            itemResponder = new ItemResponder(responder["getIdByGameNameResult"],responder["fault"] );
            token.addResponder(itemResponder);            	
        }
		
		public function getNameByGameId( id:String ):void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.getGameNameById(id);//需要添加这个接口
            itemResponder = new ItemResponder(responder["getNameByGameIdResult"],responder["fault"] );
            token.addResponder(itemResponder);
        }
		
		/**
		 * 查询待开发专区记录 
		 * param pageNum 页面 
		 */		
		public function getUnOpenGames(pageNum:int=0):void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.getUnOpenGames(pageNum); 
            itemResponder = new ItemResponder(responder["getGamesResult"],responder["fault"] );
            token.addResponder(itemResponder);
        }
		
		/** 返回待完善的游戏  **/
		public function getUnCompleteGames(pageNum:int=0):void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.getUnCompleteGames(pageNum); 
            itemResponder = new ItemResponder(responder["getGamesResult"],responder["fault"] );
            token.addResponder(itemResponder);
        }
		
		
        
		/** 查询待开发专区记录总条数		 */		
		public function getCountsReadyOpen():void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.getCountsReadyOpen();
            itemResponder = new ItemResponder(responder["getCountsReadyOpenResult"],responder["fault"] );
            token.addResponder(itemResponder);
        }
        
    }
}

